import 'package:demo/app/global.dart';
import 'package:demo/theme/app_colors.dart';
import 'package:demo/theme/app_text_theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'package:get/get.dart';

import '../../../widgets/MarqueeWidget.dart';
import 'home_controller.dart';

class HomeView extends GetView<HomeController> {
  const HomeView({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color(0xfff2f6ff),
      body:  Stack(
        children: [
          getTopBg(context),
          Column(
            children: [
              SizedBox(height: 40.w),
              getTitle(),
              SizedBox(height: 10.w),
              Expanded(
                child: SingleChildScrollView(
                  child: Column(
                    children: [
                      SizedBox(height: 10.w),
                      getNotice(context),
                      SizedBox(height: 10.w),
                      getTopCard(context),
                      SizedBox(height: 18.w),
                      getMiddleCard(context),
                      SizedBox(height: 15.w),
                      getBottomCard(context),
                    ],
                  ),
                ),
              ),
            ],
          )
        ],
      ),
    );
  }

  Widget getTopBg(BuildContext context){
    return Container(
      width: context.width,
      height: context.width / 2,
      decoration: const BoxDecoration(
        gradient: LinearGradient(
          begin: Alignment.topCenter,
          end: Alignment.bottomCenter,
          colors: [
            Color_main,
            Color(0xfff2f6ff)
          ],
        ),
      ),
    );
  }
  Widget getTitle(){
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
      children: [
        SizedBox(width: 15.w),
        InkWell(
          onTap : () => controller.toDevSetting(),
          child: Text(Global.APP_NAME,style: text_white_24b)),
        SizedBox(width: 15.w),
        Expanded(child: Text('年轻尽享信用分期生活',style: text_white_16)),
        InkWell(
            onTap: controller.call,
            child: Image.asset("assets/images/ic_service.png", width: 20.w, height: 20.w,color: Color_white)
        ),
        SizedBox(width: 15.w),
      ],
    );
  }
  Widget getNotice(BuildContext context){
    List<String> list = ['${Global.APP_NAME}的工作人员不会以任何方式要求您转账！'];
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 15.w),
      decoration: BoxDecoration(
        color: Color_white,
        borderRadius: BorderRadius.all(Radius.circular(20.w)),
      ),
      margin: EdgeInsets.symmetric(horizontal: 15.w),
      width: context.width - 30.w,
      height: 30.w,
      child: Row(
        children: [
          Image.asset("assets/images/ic_notice.png", width: 15.w, height: 15.w,color: Color_131732),
          SizedBox(width: 10.w),
          SizedBox(
            height: 15.w,
            width: context.width - 30.w - 30.w - 30.w,
            child: MarqueeWidget(
              itemBuilder: (BuildContext context, int index) {
                String itemStr = list[index];
                return Text(itemStr,style: text_grey_12);
              },
              count: list.length, // 循环的提示消息数量
            ),
          ),
        ],
      ),
    );
  }
  Widget getTopCard(BuildContext context){
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 15.w),
      decoration: BoxDecoration(
        color: Color_white,
        borderRadius: BorderRadius.all(Radius.circular(12.w)),
      ),
      margin: EdgeInsets.symmetric(horizontal: 15.w),
      width: context.width - 30.w,
      child: Column(
        crossAxisAlignment : CrossAxisAlignment.start,
        children: [
          SizedBox(height: 15.w),
          Text('最高可借额度（元）',style: text_131732_16),
          SizedBox(height: 18.w),
          Row(
              mainAxisAlignment : MainAxisAlignment.spaceBetween,
              children: [
                Row(
                    crossAxisAlignment : CrossAxisAlignment.end,
                    children: [
                      Text('￥',style: text_131732_18).marginOnly(bottom: 6.w),
                      SizedBox(width: 0.w),
                      Text('200,000',style: text_131732_40b),
                    ]),
                TextButton(
                    style: TextButton.styleFrom(
                        backgroundColor: Color_main,
                        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(40.w))
                    ),
                    onPressed: controller.apply,
                    child: Text('我要借款',style: text_white_16).marginSymmetric(horizontal: 12.w)
                ),
              ]),
          SizedBox(height: 20.w),
          Row(
              mainAxisAlignment : MainAxisAlignment.spaceBetween,
              children: [
                SizedBox(width: 0.w),
                Row(children: [
                  Image.asset("assets/images/ic_home_ok.png", width: 12.w, height: 12.w),
                  SizedBox(width: 6.w),
                  Text('通过率高',style: text_main_14),
                ]),
                Row(children: [
                  Image.asset("assets/images/ic_home_ok.png", width: 12.w, height: 12.w),
                  SizedBox(width: 6.w),
                  Text('利率超低',style: text_main_14),
                ]),
                Row(children: [
                  Image.asset("assets/images/ic_home_ok.png", width: 12.w, height: 12.w),
                  SizedBox(width: 6.w),
                  Text('极速放款',style: text_main_14),
                ]),
                SizedBox(width: 0.w),
              ]),
          SizedBox(height: 15.w),
        ],
      ),
    );
  }
  Widget getMiddleCard(BuildContext context){
    return Container(
      padding: EdgeInsets.only(left: 15.w,right:15.w,top: 12.w,bottom: 15.w),
      decoration: BoxDecoration(
        color: Color_white,
        borderRadius: BorderRadius.all(Radius.circular(12.w)),
      ),
      margin: EdgeInsets.symmetric(horizontal: 15.w),
      width: context.width - 30.w,
      child: Row(
        mainAxisAlignment : MainAxisAlignment.spaceBetween,
        children: [
          InkWell(
            onTap: () => controller.apply(),
            child: Column(children: [
              Image.asset("assets/images/ic_home_1.png", width: 60.w, height: 60.w),
              Text('极速借款',style: text_131732_14),
            ]),
          ),
          InkWell(
            onTap: () => controller.toOrder(0),
            child: Column(children: [
              Image.asset("assets/images/ic_home_2.png", width: 60.w, height: 60.w),
              Text('还款查询',style: text_131732_14),
            ]),
          ),
          InkWell(
            onTap: () => controller.toOrder(0),
            child: Column(children: [
              Image.asset("assets/images/ic_home_3.png", width: 60.w, height: 60.w),
              Text('借款记录',style: text_131732_14),
            ]),
          ),
          InkWell(
            onTap: () => controller.toCalc(),
            child: Column(children: [
              Image.asset("assets/images/ic_home_4.png", width: 60.w, height: 60.w),
              Text('利息计算器',style: text_131732_14),
            ]),
          ),
        ],
      ),
    );
  }
  Widget getBottomCard(BuildContext context){
    var imageWidth = (context.width - 30.w - 20.w) / 3;
    var imageHeight = imageWidth * 275 / 226;
    return Column(
      children: [
        Row(children: [
          Container(
              width: 5.w,
              height: 18.w,
              margin: EdgeInsets.only(left: 15.w,right: 10.w),
              decoration: BoxDecoration(
                color: Color_main,
                borderRadius: BorderRadius.all(Radius.circular(12.w)),
              )),
          Text('热门功能',style: text_131732_18)
        ]),
        SizedBox(height: 15.w),
        Row(
            mainAxisAlignment : MainAxisAlignment.spaceBetween,
            children: [
              InkWell(
                onTap: ()=> controller.toHint(0),
                child: Container(
                  padding: EdgeInsets.only(left: 15.w),
                  margin: EdgeInsets.only(left: 15.w),
                  decoration: const BoxDecoration(
                    image: DecorationImage(image: AssetImage("assets/images/ic_home_5.png")),
                  ),
                  width: imageWidth,
                  height: imageHeight,
                  child: Column(
                      crossAxisAlignment : CrossAxisAlignment.start,
                      children: [
                        SizedBox(height: 12.w),
                        Text('借款指南',style: text_white_18b),
                        SizedBox(height: 6.w),
                        Text('操作详情',style: text_white_14),
                      ]),
                ),
              ),
              InkWell(
                onTap: ()=> controller.toHint(1),
                child: Container(
                  padding: EdgeInsets.only(left: 15.w),
                  decoration: const BoxDecoration(
                    image: DecorationImage(image: AssetImage("assets/images/ic_home_6.png")),
                  ),
                  width: imageWidth,
                  height: imageHeight,
                  child: Column(
                      crossAxisAlignment : CrossAxisAlignment.start,
                      children: [
                        SizedBox(height: 12.w),
                        Text('还款指南',style: text_white_18b),
                        SizedBox(height: 6.w),
                        Text('还款操作',style: text_white_14),
                      ]),
                ),
              ),
              InkWell(
                onTap: ()=> controller.toAbout(),
                child: Container(
                  padding: EdgeInsets.only(left: 15.w),
                  margin: EdgeInsets.only(right: 15.w),
                  decoration: const BoxDecoration(
                    image: DecorationImage(image: AssetImage("assets/images/ic_home_7.png")),
                  ),
                  width: imageWidth,
                  height: imageHeight,
                  child: Column(
                      crossAxisAlignment : CrossAxisAlignment.start,
                      children: [
                        SizedBox(height: 12.w),
                        Text('防骗提醒',style: text_white_18b),
                        SizedBox(height: 6.w),
                        Text('提高安全意识',style: text_white_14),
                      ]),
                ),
              ),
            ]),
        SizedBox(height: 15.w),
        Row(children: [
          Container(
              width: 5.w,
              height: 18.w,
              margin: EdgeInsets.only(left: 15.w,right: 10.w),
              decoration: BoxDecoration(
                color: Color_main,
                borderRadius: BorderRadius.all(Radius.circular(12.w)),
              )),
          Text('新手必读',style: text_131732_18)
        ]),
        SizedBox(height: 15.w),
        Container(
          padding: EdgeInsets.symmetric(horizontal: 35.w,vertical: 15.w),
          decoration: BoxDecoration(
            color: Color_white,
            borderRadius: BorderRadius.all(Radius.circular(12.w)),
          ),
          margin: EdgeInsets.symmetric(horizontal: 15.w),
          width: context.width - 30.w,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              InkWell(
                onTap: ()=> controller.toHint(2),
                child: Column(children: [
                  Container(
                      padding: EdgeInsets.all(6.w),
                      decoration: BoxDecoration(
                        border: Border.all(color: Color_main, width: 1.0),
                        borderRadius: BorderRadius.all(Radius.circular(40.w)),
                      ),
                      child: Image.asset("assets/images/ic_home_8.png", width: 25.w, height: 25.w,color: Color_main)),
                  SizedBox(height: 6.w),
                  Text('完善信息', style: text_131732_14),
                ]),
              ),
              InkWell(
                onTap: ()=> controller.toHint(3),
                child: Column(children: [
                  Container(
                      padding: EdgeInsets.all(6.w),
                      decoration: BoxDecoration(
                        border: Border.all(color: Color_main, width: 1.0),
                        borderRadius: BorderRadius.all(Radius.circular(40.w)),
                      ),
                      child: Image.asset("assets/images/ic_home_9.png", width: 25.w, height: 25.w,color: Color_main)),
                  SizedBox(height: 6.w),
                  Text('极速审核', style: text_131732_14),
                ]),
              ),
              InkWell(
                onTap: ()=> controller.toHint(4),
                child: Column(children: [
                  Container(
                      padding: EdgeInsets.all(6.w),
                      decoration: BoxDecoration(
                        border: Border.all(color: Color_main, width: 1.0),
                        borderRadius: BorderRadius.all(Radius.circular(40.w)),
                      ),
                      child: Image.asset("assets/images/ic_home_10.png", width: 25.w, height: 25.w,color: Color_main)),
                  SizedBox(height: 6.w),
                  Text('立即放款', style: text_131732_14),
                ]),
              ),
            ],
          ),
        ),
        SizedBox(height: 15.w)
      ],
    );
  }
}